package de.ifi.lmu.snitzelhunt.view;

import java.util.ArrayList;

import de.ifi.lmu.snitzelhunt.R;
import de.ifi.lmu.snitzelhunt.basics.ActionTask;
import de.ifi.lmu.snitzelhunt.basics.ImageTask;
import de.ifi.lmu.snitzelhunt.basics.QuizTask;
import de.ifi.lmu.snitzelhunt.basics.Task;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class TaskListViewAdapter extends ArrayAdapter<Task> {
	private final Context context;
	private final ArrayList<Task> values;
	
	private TextView detail;
	private TextView taskType;
	private ImageView taskIcon;

	public TaskListViewAdapter(Context context, ArrayList<Task> values) {
		super(context, R.layout.create_hunt_tasklist_layout,values);
		this.context = context;
		this.values = values;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View rowView = inflater.inflate(R.layout.create_hunt_tasklist_layout, parent, false);
		
		detail = (TextView) rowView.findViewById(R.id.taskListDetail);
		taskType = (TextView) rowView.findViewById(R.id.taskListType);
		taskIcon = (ImageView) rowView.findViewById(R.id.creat_list_task_icon);
		
		Log.i("Adapter", "detail:"+(detail!=null));
		detail.setText(values.get(position).getDetail());
		
		
		if (values.get(position).getClass() == QuizTask.class) {
			taskType.setText(R.string.title_activity_quiz);
			taskIcon.setImageResource(R.drawable.questionicon);
		} else if (values.get(position).getClass() == ActionTask.class) {
			taskType.setText(R.string.title_activity_action_task);
			taskIcon.setImageResource(R.drawable.actionicon);
		} else if (values.get(position).getClass() == ImageTask.class) {
			taskType.setText(R.string.title_activity_activity__image_task);
			taskIcon.setImageResource(R.drawable.image_task);
		}
		
		return rowView;
	}
	
	
}
